import tkinter as tk
from tkinter import messagebox


def sakamoto(y, m, d):
    # 每月的偏移表（Sakamoto 算法的核心）
    t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]

    # 如果月份 < 3，年份减 1（处理闰年）
    if m < 3:
        y -= 1

    # Sakamoto 公式
    return (y + y // 4 - y // 100 + y // 400 + t[m - 1] + d) % 7

def submit():
    year = int(entry_year.get())
    mon = int(entry_mon.get())
    day = int(entry_day.get())

    wday = sakamoto(year, mon, day)

    messagebox.showinfo(f"今天是周{wday}")

# 创建主窗口
root = tk.Tk()
root.title("算算今天是周几？")

# 添加标签和输入框
# tk.Label(root, text="年:").grid(row=0, column=0, padx=10, pady=5)
# entry_year = tk.Entry(root)
# entry_year.grid(row=0, column=1, padx=10, pady=5)
#
# tk.Label(root, text="月:").grid(row=1, column=0, padx=10, pady=5)
# entry_mon = tk.Entry(root)
# entry_mon.grid(row=1, column=1, padx=10, pady=5)
#
# tk.Label(root, text="日:").grid(row=2, column=0, padx=10, pady=5)
# entry_day = tk.Entry(root)
# entry_day.grid(row=2, column=1, padx=10, pady=5)

tk.Label(root, text="年:").pack(pady=5)
entry_year = tk.Entry(root)
entry_year.pack(pady=5)

tk.Label(root, text="月:").pack(pady=5)
entry_mon = tk.Entry(root)
entry_mon.pack(pady=5)

tk.Label(root, text="日:").pack(pady=5)
entry_day = tk.Entry(root)
entry_day.pack(pady=5)

# 添加提交按钮
submit_btn = tk.Button(root, text="提交", command=submit)
# submit_btn.grid(row=3, column=0, columnspan=3, pady=10)
submit_btn.pack(pady=2)

# 运行主循环
root.mainloop()